$(function (){
    //获取权限列表
    $.ajax({
        url: baseNews + '/api/data/role/list',
        success:function (res){
            console.log(res,6666);
            if(res.code==0){
                var list=res.data;
                var html='';
                $(list).each(function (index,key){
                    html +=`<tr>
								<label><td class="shfb1">${key.name}</td>
								<td class="dx1"><input name="shfb" class="roleid" data-id="${key.id}" type="radio" value="" /></td>
								</label>
							</tr>`;
                })
                $(".qx_list").append(html);
            }
        }
    })
    //创建
    $('.baocun').on('click',function (){
        var username = $(".username").val();//用户名
        var pass = $(".pass").val();//密码
        var passd = $(".passd").val();//重复密码
        var email = $(".email").val();//邮箱
        var unicheng = $(".unicheng").val();//昵称
        if (username==""){
            zeroModal.alert("请输入用户名");
            return;
        }
        if (pass == "") {
            zeroModal.alert("请输入密码");
            return;
        }
        if (pass != passd){
            zeroModal.alert("请两次密码输入一致");
            return;
        }
        var roid='';
        $(".roleid").each(function (index,key){
            var isprop=$(this).attr("data-id");
            console.log($(this).prop("checked"));
            if ($(this).prop("checked")==true){
                roid = isprop;
            }
        })
        var jsonList={
            "confirm": passd,
            "email": email,
            "nickname": unicheng,
            "pwd": pass,
            "role": roid,
            "username": username
        };
        console.log(jsonList);
        var result = JSON.stringify(jsonList);
        $.ajax({
            url: baseNews + "/api/data/user/add",
            type: "post",
            headers: { 'Content-Type': 'application/json' },
            dataType: "json",
            data: result,
            success: function (res) {
                if (res.code == 0) {
                    zeroModal.alert("增加成功");
                    setTimeout(() => {
                        location.reload();
                    }, 2000);
                } else {
                    zeroModal.alert('增加用户失败');
                }
            }
        })
    })
})